package com.itheima.map;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @Author 王加鑫
 * @Date 2021/5/16 15:54
 * @Version 1.0
 */
public class MapDemo03 {
    public static void main(String[] args) {
        Map<String,String> map = new HashMap<>();
        map.put("001","张三");
        map.put("002","李四");
        map.put("003","王五");
        map.put("004","赵六");
        map.put("005","叶凡");
        map.put("006","悟空");

        //获取所有的键
        Set<String> keySet = map.keySet();
        //遍历set集合得到每一个键
        for (String key : keySet) {
            //通过键获取value
            String value = map.get(key);
            System.out.println(key + "=" + value);
        }

        System.out.println("========================");

        Set<Map.Entry<String, String>> entrySet = map.entrySet();
        for (Map.Entry<String, String> entry : entrySet) {
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key + "=" + value);
        }

        System.out.println("===============================");

        map.forEach((k,v) -> System.out.println(k + "=" + v) );
    }
}
